(function () {
    var fullScreenApi = {
            supportsFullScreen:false,
            isFullScreen:function () {
                return false;
            },
            requestFullScreen:function () {
            },
            cancelFullScreen:function () {
            },
            fullScreenEventName:'',
            prefix:''
        },
        browserPrefixes = 'webkit moz o ms khtml'.split(' ');

    if (typeof document.cancelFullScreen != 'undefined') {
        fullScreenApi.supportsFullScreen = true;
    } else {
        for (var i = 0, il = browserPrefixes.length; i < il; i++) {
            fullScreenApi.prefix = browserPrefixes[i];

            if (typeof document[fullScreenApi.prefix + 'CancelFullScreen' ] != 'undefined') {
                fullScreenApi.supportsFullScreen = true;

                break;
            }
        }
    }

    if (fullScreenApi.supportsFullScreen) {
        fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange';

        fullScreenApi.isFullScreen = function () {
            switch (this.prefix) {
                case '':
                    return document.fullScreen;
                case 'webkit':
                    return document.webkitIsFullScreen;
                default:
                    return document[this.prefix + 'FullScreen'];
            }
        }
        fullScreenApi.requestFullScreen = function (el) {
            return (this.prefix === '') ? el.requestFullScreen() : el[this.prefix + 'RequestFullScreen']();
        }
        fullScreenApi.cancelFullScreen = function (el) {
            return (this.prefix === '') ? document.cancelFullScreen() : document[this.prefix + 'CancelFullScreen']();
        }
    }
    window.fullScreenApi = fullScreenApi;
})();

function trigfullScreen(fsElement) {
    if (window.fullScreenApi.supportsFullScreen) {
        window.fullScreenApi.requestFullScreen(fsElement);
    } else {
        alert('SORRY: Your browser does not support FullScreen!');
    }
}

function fullScreen(fsButton, fsElement) {
    if (window.fullScreenApi.supportsFullScreen) {
        // handle button click
        fsButton.addEventListener('click', function () {
            window.fullScreenApi.requestFullScreen(fsElement);
        }, true);

        fsElement.addEventListener(fullScreenApi.fullScreenEventName, function () {
            if (fullScreenApi.isFullScreen()) {
                //fsStatus.innerHTML = 'Whoa, you went fullscreen';
            } else {

            }
        }, true);

    } else {
        alert('SORRY: Your browser does not support FullScreen!');
    }
}
